﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace LocalizationLibrary.Tests.Core.Attributes
{
    //.NET References
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;

    // Microsoft References
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    //LocalizationLibrary Referenes
    using LocalizationLibrary.Attributes;

    [TestClass]
    public class LocalizeDynamicallyAttributeTest
    {
        [TestMethod]
        public void New_Instance_Should_Assigns_All_Properties()
        {
            LocalizeDynamicallyAttribute instance1 = new LocalizeDynamicallyAttribute();
            Assert.AreEqual(instance1.ResourceID, null);

            String resourceID = Guid.NewGuid().ToString();
            LocalizeDynamicallyAttribute instance2 = new LocalizeDynamicallyAttribute(resourceID);
            Assert.AreEqual(instance2.ResourceID, resourceID);

            LocalizeDynamicallyAttribute instance3 = new LocalizeDynamicallyAttribute(resourceID, null, null);
            Assert.AreEqual(instance3.ResourceID, resourceID);
            Assert.AreEqual(instance3.Language, null);
            Assert.AreEqual(instance3.Value, null);

            String language = Language.DefaultLanguage.Code;
            String text = Guid.NewGuid().ToString();

            LocalizeDynamicallyAttribute instance4 = new LocalizeDynamicallyAttribute(resourceID,language, text);
            Assert.AreEqual(instance4.ResourceID, resourceID);
            Assert.AreEqual(instance4.Language, language);
            Assert.AreEqual(instance4.Value, text);
        }

        [TestMethod]
        public void All_Properties_Are_Assigned()
        {
            String languageStr = "it";
            LocalizeDynamicallyAttribute instance1 = new LocalizeDynamicallyAttribute();
            instance1.Language = languageStr;
            Assert.AreEqual(instance1.Language, languageStr);

            instance1.Policy = VersionConflictPolicy.KeepExisting;
            Assert.AreEqual(instance1.Policy, VersionConflictPolicy.KeepExisting);

            instance1.Policy = VersionConflictPolicy.OverrideExisting;
            Assert.AreEqual(instance1.Policy, VersionConflictPolicy.OverrideExisting);
        }

        [TestMethod]
        public void GetHashCode_Should_Be_Always_The_Same()
        {
            String resourceId = Guid.NewGuid().ToString();
            LocalizeDynamicallyAttribute instance = new LocalizeDynamicallyAttribute(resourceId);
            Assert.AreEqual(instance.GetHashCode(), resourceId.GetHashCode());
        }

        [TestMethod]
        public void GetHashCode_Should_Be_Not_Equal()
        {
            LocalizeDynamicallyAttribute instance = new LocalizeDynamicallyAttribute(null);
            LocalizeDynamicallyAttribute instance2 = new LocalizeDynamicallyAttribute(null);
            Assert.AreNotEqual(instance.GetHashCode(), instance2.GetHashCode());
        }

        [TestMethod]
        public void Verify_If_Two_Instance_Are_Equals()
        {
            String resourceId = Guid.NewGuid().ToString();
            LocalizeDynamicallyAttribute instance = new LocalizeDynamicallyAttribute(resourceId);

            Assert.AreEqual(instance.Equals(null), false);
            Assert.AreEqual(instance.Equals(instance), true);

            LocalizeDynamicallyAttribute instance2 = new LocalizeDynamicallyAttribute(resourceId);

            Assert.AreEqual(instance.Equals(instance2), true);

            instance2 = new LocalizeDynamicallyAttribute(Guid.NewGuid().ToString());

            Assert.AreEqual(instance.Equals(instance2), false);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void Thrown_ArgumentException_If_Language_Is_Not_Valide()
        {
            String languageStr = "xxxx";
            LocalizeDynamicallyAttribute instance = new LocalizeDynamicallyAttribute(Guid.NewGuid().ToString());
            instance.Language = languageStr;
        }
    }
}
